import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { LocalStorage } from "../utils/localstorage";
import { NotifyService } from "../utils/notify.service";

@Component({
  selector: 'app-token',
  template: ""
})
export class TokenComponent implements OnInit {

  constructor(private notify: NotifyService,private actRouter: ActivatedRoute, private router: Router) {
  }

  ngOnInit() {
    LocalStorage.removeToken();
    this.actRouter.queryParamMap.subscribe((params : ParamMap) => {
      let token = params.keys.length===1 ? params.keys[0] : '';
      if (token) {
        LocalStorage.saveToken(token);
        this.router.navigateByUrl('wel').then();
      } else {
        this.notify.error("请提供登录Token").subscribe();

      }
    });
  }

}
